﻿using System;
using System.IO;
using System.Media;
using System.Windows.Forms;

namespace TipTip
{
    public partial class TipForm : Form
    {
        private static int CLOSE_SEC = 300;
        private string STR_MIN = "";
        private int RUN_SEC = 0;

        public TipForm()
        {
            InitializeComponent();
        }

        public TipForm(string _min)
        {
            STR_MIN = _min;
            InitializeComponent();
            
            this.WindowState = FormWindowState.Maximized;
            this.TopMost = true;
            this.BringToFront();
        }

        private void TipForm_Load(object sender, EventArgs e)
        {
            label1.Text = "亲，您又工作了"+ STR_MIN + "分钟，该休息一下啦!";
            timer1.Enabled = true;

            //播放声音
            string wavFile = Application.StartupPath + @"\alarm.wav";
            Stream sm = null;
            if (File.Exists(wavFile))
            {
                sm = new FileStream(wavFile, FileMode.Open);
            } else
            {
                sm = Properties.Resources.Alarm02;
            }
            SoundPlayer player = new SoundPlayer(sm);
            player.Play();
            player.Dispose();

            if (sm != null)
            {
                sm.Close();
                sm.Dispose();
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            RUN_SEC++;
            if (RUN_SEC >= CLOSE_SEC)
            {
                RUN_SEC = 0;
                Close();
            } else
            {
                label2.Text = "[" + (CLOSE_SEC - RUN_SEC) + "秒后自动关闭]";
            }
        }

        private void TipForm_Resize(object sender, EventArgs e)
        {
            label1.Width = this.Width - 50;
            label1.Top = (this.Height - 150) / 2;
            label2.Width = label1.Width;
            label2.Top = label1.Top + 150;
        }
    }
}
